package com.lc.qianrenshiye.activity;

import android.Manifest;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.lc.qianrenshiye.BaseActivity;
import com.lc.qianrenshiye.BaseApplication;
import com.lc.qianrenshiye.R;
import com.lc.qianrenshiye.dialog.WarnningDialog;
import com.lc.qianrenshiye.uitls.MyToast;
import com.lc.qianrenshiye.uitls.UtilPermission;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.util.UtilApp;
import com.zcx.helper.util.UtilData;

/**
 * Created by Administrator on 2016/11/17.
 */
public class SettingActivity extends BaseActivity implements View.OnClickListener {

    @BoundView(R.id.setting_call_service_tv) private TextView setting_call_service_tv;
    @BoundView(R.id.setting_clean_cache_tv) private TextView setting_clean_cache_tv;
    @BoundView(R.id.setting_change_password_tv) private TextView setting_change_password_tv;
    @BoundView(R.id.setting_feedback_tv) private TextView setting_feedback_tv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_setting);

        String[] permission = {Manifest.permission.CALL_PHONE};
        UtilPermission.Permission(this, permission);

        setBackTrue();

        setTitleName(getString(R.string.center_setting_text));

        setRightName(getString(R.string.setting_title_right_text) + UtilApp.versionName(context), R.color.text_hint_color, this);



        setting_call_service_tv.setOnClickListener(this);
        setting_clean_cache_tv.setOnClickListener(this);
        setting_change_password_tv.setOnClickListener(this);
        setting_feedback_tv.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {

        switch (v.getId()) {

            case R.id.title_right_no_net_rl:

//                MyToast.showToast("versionName" + UtilApp.versionName(context) + "  versionCode" + UtilApp.versionCode(context), context);

                break;

            case R.id.setting_call_service_tv:

                new WarnningDialog(context, BaseApplication.BasePreferences.readServiceTel(), getString(R.string.dialog_cancle_text), getString(R.string.dialog_call_text)) {
                    @Override
                    protected void onConfirm() {

                        UtilApp.call(context, BaseApplication.BasePreferences.readServiceTel());

                    }
                }.show();


                break;

            case R.id.setting_clean_cache_tv:


                new WarnningDialog(context, getString(R.string.setting_clearn_cache_text), getString(R.string.dialog_cancle_text), getString(R.string.dialog_sure_text)) {
                    @Override
                    protected void onConfirm() {

                        String cacheSize = null;
                        try {
                            cacheSize = UtilData.getTotalCacheSize(context);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                        UtilData.clearAllCache(context);

                        MyToast.showToast("缓存清理完成,本次清理缓存" + cacheSize, context);

                    }
                }.show();


                break;

            case R.id.setting_change_password_tv:

                startActivity(new Intent(this, ChangePasswordActivity.class));

                break;

            case R.id.setting_feedback_tv:

                startActivity(new Intent(this, FeedbackActivity.class));

                break;
        }

    }
}
